#include <cstdio>
#include <memory.h>

int f[ 17 ][ 1 << 16 ];

int main( )
{
    int n, i, j, m, s, v, ans;
    while ( scanf("%d", &n) && n )
    {
        memset( f, 0, sizeof( f ) );
        scanf("%d", &m);
        for ( i = 0; i < m; i++ )
        {
            scanf("%d%d", &s, &v);
            f[ 0 ][ s ] = v;
        }
        for ( i = 1; i <= n; i++ )
            for ( j = 0; j < ( 1 << n ); j++ )
                if ( ( 1 << ( i - 1 ) ) & j )
                    f[ i ][ j ] = f[ i - 1 ][ j ] + f[ i - 1 ][ j ^ ( 1 << ( i - 1 ) ) ];
                else
                    f[ i ][ j ] = f[ i - 1 ][ j ];
        ans = -1000000000;
        for ( i = 0; i < ( 1 << n ); i++ )
            if ( ans < f[ n ][ i ] )
                ans = f[ n ][ i ];
        printf("%d\n", ans);
    }
    return 0;
}
